package han.chensing.latos.load;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector2;

import han.chensing.latos.V;
import han.chensing.latos.res.Res;

public class LoadScreen implements Screen {

    Texture loadTexture;
    Texture loadTextTexture;
    SpriteBatch spriteBatch;
    int initSpeed=250;
    Vector2 speed=new Vector2(0,0);
    Vector2 aSpeed=new Vector2(0,-1000f);
    Color color = Color.valueOf("#52B4FFFF");
    float y;

    public LoadScreen(){
        loadTexture=new Texture("game/loading/Loading.png");
        loadTextTexture=new Texture("game/loading/LoadingText.png");
        spriteBatch=new SpriteBatch();
    }

    @Override
    public void show() {
        y=0;
    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(0,0,0, 1f);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        V.globalViewport.apply(true);
        spriteBatch.setProjectionMatrix(V.globalCamera.combined);
        spriteBatch.begin();
        spriteBatch.draw(loadTexture, 10,80);
        speed.mulAdd(aSpeed,delta);
        if (y<=0){
            speed.y=initSpeed;
        }
        y+=speed.y*delta;
        spriteBatch.draw(loadTextTexture,20,-10);
        spriteBatch.end();
        V.shapeRenderer.setProjectionMatrix(V.globalCamera.combined);
        V.shapeRenderer.setColor(Color.WHITE);
        V.shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
        V.shapeRenderer.rectLine(
                0,2.5f,
                V.WIDTH*((float) Res.getInstance().getLoadedTotal()/Res.getInstance().getLoadTotal()),2.5f,
                8f, color,color);
        V.shapeRenderer.end();
        V.shapeRenderer.run();
    }

    @Override
    public void resize(int width, int height) {
        V.globalViewport.update(width, height,true);
    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void hide() {

    }

    @Override
    public void dispose() {
        loadTexture.dispose();
        loadTextTexture.dispose();
    }
}
